/***************************************************************************
 **
 **    This file defines the board specific definition
 **
 **    Used with ARM IAR C/C++ Compiler and Assembler.
 **
 **    (c) Copyright IAR Systems 2005
 **
 **    $Revision: 36578 $
 **
 ***************************************************************************/
#include <intrinsics.h>
#include "arm_comm.h"

#ifndef __BOARD_H
#define __BOARD_H

#define I_RC_OSC_FREQ   (12MHZ)
#define MAIN_OSC_FREQ   (12MHZ)
#define WDT_OSC_FREQ    (0MHZ)

#define PIN_LOW(pin)   pin = 0
#define PIN_HIGH(pin)  pin = 0x7FF

// LED1
#define LED1_MASK   (1UL<<3)
#define LED1_DIR    GPIO0DIR
#define LED1_PIN    (*((volatile unsigned int *)(0x50000000+(LED1_MASK<<2))))
// LED2
#define LED2_MASK   (1UL<<6)
#define LED2_DIR    GPIO0DIR
#define LED2_PIN    (*((volatile unsigned int *)(0x50000000+(LED2_MASK<<2))))

// LED3
#define LED3_MASK   (1UL<<3)
#define LED3_DIR    GPIO0DIR
#define LED3_PIN    (*((volatile unsigned int *)(0x50000000+(LED3_MASK<<2))))

// LED4
#define LED4_MASK   (1UL<<6)
#define LED4_DIR    GPIO0DIR
#define LED4_PIN    (*((volatile unsigned int *)(0x50000000+(LED4_MASK<<2))))

// LED5
#define LED5_MASK   (1UL<<7)
#define LED5_DIR    GPIO0DIR
#define LED5_PIN    (*((volatile unsigned int *)(0x50000000+(LED5_MASK<<2))))

// LED6
#define LED6_MASK   (1UL<<8)
#define LED6_DIR    GPIO0DIR
#define LED6_PIN    (*((volatile unsigned int *)(0x50000000+(LED6_MASK<<2))))

// LED7
#define LED7_MASK   (1UL<<9)
#define LED7_DIR    GPIO0DIR
#define LED7_PIN    (*((volatile unsigned int *)(0x50000000+(LED7_MASK<<2))))

// LED8
#define LED8_MASK   (1UL<<10)
#define LED8_DIR    GPIO0DIR
#define LED8_PIN    (*((volatile unsigned int *)(0x50000000+(LED8_MASK<<2))))

// LED9
#define LED9_MASK   (1UL<<11)
#define LED9_DIR    GPIO0DIR
#define LED9_PIN    (*((volatile unsigned int *)(0x50000000+(LED9_MASK<<2))))

// LED10
#define LED10_MASK  (1UL<<2)
#define LED10_DIR   GPIO3DIR
#define LED10_PIN   (*((volatile unsigned int *)(0x50030000+(LED10_MASK<<2))))

// LED11
#define LED11_MASK  (1UL<<4)
#define LED11_DIR   GPIO3DIR
#define LED11_PIN   (*((volatile unsigned int *)(0x50030000+(LED11_MASK<<2))))


// LED12
#define LED12_MASK  (1UL<<5)
#define LED12_DIR   GPIO3DIR
#define LED12_PIN   (*((volatile unsigned int *)(0x50030000+(LED12_MASK<<2))))

// LED13
#define LED13_MASK  (1UL<<4)
#define LED13_DIR   GPIO1DIR
#define LED13_PIN   (*((volatile unsigned int *)(0x50010000+(LED13_MASK<<2))))

#define LED_OFF(pin) PIN_LOW(pin)
#define LED_ON(pin)  PIN_HIGH(pin)

//HabTx
#define HAB_TX_MASK   	(1UL<<5)
#define HAB_TX_DIR		GPIO1DIR
#define	TX_PIN	  		(*((volatile unsigned int *)(0x50010000+(HAB_TX_MASK<<2))))

#define DES_HAB_TX(pin)		PIN_LOW(pin)
#define HAB_TX(pin)			PIN_HIGH(pin)

//HabRx
#define HAB_RX_MASK   	(1UL<<8)
#define HAB_RX_DIR    	GPIO1DIR
#define	RX_PIN	  		(*((volatile unsigned int *)(0x50010000+(HAB_RX_MASK<<2))))

#define DES_HAB_RX(pin)		PIN_HIGH(pin)
#define HAB_RX(pin)			PIN_LOW(pin)

//Linha 1
#define L1_MASK   (1UL<<3)
#define L1_DIR    GPIO1DIR
#define	L1_PIN	  (*((volatile unsigned int *)(0x50010000+(L1_MASK<<2))))

//Linha 2
#define L2_MASK   (1UL<<9)
#define L2_DIR    GPIO1DIR
#define	L2_PIN	  (*((volatile unsigned int *)(0x50010000+(L2_MASK<<2))))

//Linha 3
#define L3_MASK   (1UL<<10)
#define L3_DIR    GPIO1DIR
#define	L3_PIN	  (*((volatile unsigned int *)(0x50010000+(L3_MASK<<2))))

#define DES_HAB_LINHA(pin)		PIN_HIGH(pin)
#define HAB_LINHA(pin)			PIN_LOW(pin)

// Buttons
//B1 SW10
#define B1_MASK           (1UL<<11)
#define B1_DIR            GPIO1DIR
#define B1_PIN            (*((volatile unsigned int *)(0x50010000+ (B1_MASK<<2))))
//B2 SW11
#define B2_MASK           (1UL<<0)
#define B2_DIR            GPIO2DIR
#define B2_PIN            (*((volatile unsigned int *)(0x50020000+ (B2_MASK<<2))))

//C1 coluna de teclas 1
#define C1_MASK           (1UL<<0)
#define C1_DIR            GPIO1DIR
#define C1_PIN            (*((volatile unsigned int *)(0x50010000+ (C1_MASK<<2))))

//C2 coluna de teclas 2
#define C2_MASK           (1UL<<1)
#define C2_DIR            GPIO1DIR
#define C2_PIN            (*((volatile unsigned int *)(0x50010000+ (C2_MASK<<2))))

//C3 coluna de teclas 3
#define C3_MASK           (1UL<<2)
#define C3_DIR            GPIO1DIR
#define C3_PIN            (*((volatile unsigned int *)(0x50010000+ (C3_MASK<<2))))

//UART
#define UART_TX_MASK   (1UL<<7)
#define UART_TX_DIR    GPIO1DIR
#define UART_TX_PIN   (*((volatile unsigned int *)(0x50010000+(UART_TX_MASK<<2))))
#define UART_TX_IOCON        IOCON_PIO1_7

#define UART_RX_MASK   (1UL<<6)
#define UART_RX_DIR    GPIO1DIR
#define UART_RX_PIN   (*((volatile unsigned int *)(0x50010000+(UART_RX_MASK<<2))))
#define UART_RX_IOCON        IOCON_PIO1_6

#endif /* __BOARD_H */
